import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lcapp/api/interface/user_api.dart';
import 'package:lcapp/api/request/response_data.dart';
import 'package:lcapp/model/event/event_bus.dart';
import 'package:lcapp/model/toast/toast.dart';

class ReginPage extends StatefulWidget {
  const ReginPage({Key? key}) : super(key: key);

  @override
  _ReginPageState createState() => _ReginPageState();
}

class _ReginPageState extends State<ReginPage> {
  TextEditingController codeController =  TextEditingController();
  String get code => codeController.text;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      backgroundColor: const Color(0xffFCFCFC),
      body:  Container(
        padding: EdgeInsets.symmetric(horizontal: 30.w),
        child: Column(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            GestureDetector(
              onTap: (){
                Navigator.of(context).pop();
                eventBus.fire(LoginState());
              },
              child: Container(
                alignment: Alignment.centerLeft,
                margin: EdgeInsets.only(top: 150.w),
                child: const Icon(Icons.arrow_back_ios_outlined,size: 30,color: Colors.black,),
              ),
            ),
            Container(
              width: double.infinity,
              margin: EdgeInsets.only(top: 50.w),
              child:  Text('注册',style: TextStyle(
                  color: Colors.black,
                  fontSize: 46.sp,
                  fontWeight: FontWeight.bold
              ),),
            ),
            Container(
              margin: EdgeInsets.only(top: 20.w),
              width: double.infinity,
              child:  Text('请输入邀请码',style: TextStyle(
                color: const Color(0xffAEAEAE),
                fontSize: 26.sp,
              ),),
            ),
            Container(
              margin: EdgeInsets.only(top: 15.w),
              height: 88.w,
              child: TextField(
                controller: codeController,
                textInputAction: TextInputAction.done,
                maxLength: 11,
                maxLines: 1,
                // cursorColor: Color(0xFFFF3000),
                autocorrect: true,
                autofocus: false,
                decoration:  InputDecoration(
                  contentPadding: EdgeInsets.only(left: 17.w),
                  hintText: "邀请码（没有请点击跳过）",
                  hintStyle: TextStyle(
                    color: const Color(0xFFAEAEAE),
                    fontSize: 26.sp,
                    fontWeight: FontWeight.w500,
                  ),
                  counterText: "",
                  border: const OutlineInputBorder(
                    borderSide: BorderSide.none,
                  ),
                  fillColor: const Color(0xFFF8F8F8),
                  filled: true,
                ),
              ),
            ),

            GestureDetector(
              onTap: ()async{
                if(codeController.text.trim().isEmpty){
                  showToast('请输入邀请码');
                  return;
                }
                showLoading();
                ResponseData res = await UserAPI.bindInvite(codeController.text.trim());
                hideLoading();
                if(res.code==200){
                  Navigator.of(context).pop();
                  eventBus.fire(LoginState());
                }
              },
              child: Container(
                height: 88.w,
                width: double.infinity,
                alignment: Alignment.center,
                margin: EdgeInsets.only(top: 30.w),
                decoration: BoxDecoration(
                  color: const Color(0xffFA6E28), // 渐变色
                  borderRadius: BorderRadius.circular(6.w),
                ),
                child: Text(
                  '下一步',
                  style: TextStyle(
                      color: Colors.white, fontSize: 30.sp),
                ),
              ),
            ),
            GestureDetector(
              onTap: (){
                Navigator.of(context).pop();
                eventBus.fire(LoginState());
              },
              child: Container(
                alignment: Alignment.center,
                margin: EdgeInsets.only(top: 30.w),
                child: Text(
                  '跳过',
                  style: TextStyle(
                      color: Color(0xffFA6E28), fontSize: 30.sp,fontWeight: FontWeight.w600),
                ),
              ),
            ),

          ],
        ),
      ),
    );
  }
}
